usbcpower2 2.2.0
Loading...
Searching...
No Matches
usbcpower2


USB-C Power 2 Click

USB-C Power 2 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Mar 2026.
  • Type : I2C type

Software Support

Example Description

This example demonstrates the use of the USB-C Power 2 Click board for detecting USB cable attachment and monitoring CC (Configuration Channel) status. The application reads interrupt and CC status registers and logs the interpreted results to the serial terminal.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.USBCPower2

Example Key Functions

  • usbcpower2_cfg_setup This function initializes Click configuration structure to initial values.
    void usbcpower2_cfg_setup(usbcpower2_cfg_t *cfg)
    USB-C Power 2 configuration object setup function.
    USB-C Power 2 Click configuration object.
    Definition usbcpower2.h:256
  • usbcpower2_init This function initializes all necessary pins and peripherals used for this Click board.
    err_t usbcpower2_init(usbcpower2_t *ctx, usbcpower2_cfg_t *cfg)
    USB-C Power 2 initialization function.
    USB-C Power 2 Click context object.
    Definition usbcpower2.h:238
  • usbcpower2_default_cfg This function executes a default configuration of USB-C Power 2 Click board.
    err_t usbcpower2_default_cfg(usbcpower2_t *ctx)
    USB-C Power 2 default configuration function.
  • usbcpower2_check_com This function checks communication with the device by reading the vendor ID register and validating the returned value.
    err_t usbcpower2_check_com(usbcpower2_t *ctx)
    USB-C Power 2 communication check function.
  • usbcpower2_get_int_pin This function reads and returns the logic state of the INT pin.
    uint8_t usbcpower2_get_int_pin(usbcpower2_t *ctx)
    USB-C Power 2 get INT pin function.
  • usbcpower2_read_reg This function reads a single byte of data from the selected readable register address.
    err_t usbcpower2_read_reg ( usbcpower2_t *ctx, uint8_t reg, uint8_t *data_out );
    err_t usbcpower2_read_reg(usbcpower2_t *ctx, uint8_t reg, uint8_t *data_out)
    USB-C Power 2 read register function.

Application Init

Initializes the logger and USB-C Power 2 Click driver, and applies the default device configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
usbcpower2_cfg_t usbcpower2_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
usbcpower2_cfg_setup( &usbcpower2_cfg );
if ( I2C_MASTER_ERROR == usbcpower2_init( &usbcpower2, &usbcpower2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( USBCPOWER2_ERROR == usbcpower2_default_cfg ( &usbcpower2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define USBCPOWER2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition usbcpower2.h:224
void application_init(void)
Definition main.c:45
#define MIKROBUS_POSITION_USBCPOWER2
Definition main.c:30
@ USBCPOWER2_ERROR
Definition usbcpower2.h:275

Application Task

Waits for an USB detached/attached interrupt event, then reads and displays cable connection status and CC line status information including VBUS detection, Rp value, port attachment state, and cable polarity.

void application_task ( void )
{
uint8_t status = 0;
if ( !usbcpower2_get_int_pin ( &usbcpower2 ) )
{
{
log_printf ( &logger, "USB Status: " );
{
log_printf ( &logger, "Attached\r\n" );
}
{
log_printf ( &logger, "Detached\r\n" );
}
else
{
log_printf ( &logger, "Unknown\r\n" );
}
}
if ( USBCPOWER2_OK == usbcpower2_read_reg ( &usbcpower2, USBCPOWER2_REG_CC_STATUS, &status ) )
{
usbcpower2_display_cc_status ( status );
}
Delay_ms ( 10 );
}
}
#define USBCPOWER2_REG_INTERRUPT_STATUS
Definition usbcpower2.h:75
#define USBCPOWER2_REG_CC_STATUS
Definition usbcpower2.h:76
#define USBCPOWER2_INTERRUPT_STATUS_CABLE_DETACHED
USB-C Power 2 INTERRUPT_STATUS register setting.
Definition usbcpower2.h:124
#define USBCPOWER2_INTERRUPT_STATUS_CABLE_ATTACHED
Definition usbcpower2.h:125
void application_task(void)
Definition main.c:81
@ USBCPOWER2_OK
Definition usbcpower2.h:274

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.